home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
64-bit_x64
/
Japanese
/
cpsimage.cab
/
data
/
xipProcs
/
readGS.proc
< prev
next >
Wrap
Text File
|
2009-04-23
|
3KB
|
94 lines
#load "sys/stdlib.elf";
/* @readGS
// DESCRIPTION
readGS - read GhostScript
This procedure takes in an input filename and uses GhostScript to rip the
the format type PDF or PS to raster pages in JPEG. A list of XIPIMAGES of
each page is returned to the caller. The pages are left compress to minimize
the memory footprint.
The default resolution is set at 150spi unless a specified value is
passed in to override it.
REQUIREMENTS:
Requires that the image processing classes from the xeng library have been
loaded via LoadClasses, i.e.,
LoadClasses (filename: "xeng");
It also requires that you have ghostscript available on your path. For
Windows it expects to find "gsWin32" and for Linux/UNIX it expects to find
"gs".
*/
PROCEDURE readGS (STRING filename, INTEGER resolution, STRING device)
RETURNS (ELFLIST imgs)
{
STATUS status;
STRING tempname, app, tail;
// Set processing vars; for Windows platform it will have System_Drive
if ( !device ) device = "jpeg";
if ( "$SystemDrive" != "" ) {
tempname = "$TEMP/aaaxips";
app = "gsWin32c -dNOPAUSE ";
}
else {
tempname = "/tmp/aaaxips";
app = "yes | gs ";
tail = " 2>&1 > /dev/null";
}
// Set default resolution
if ( !resolution ) resolution = 150;
// Setup command string for ghostscript. app will change if on Windows
STRING cmd = app;
cmd = cmd + " -sOutputFile=" + tempname + "%02d." + device;
cmd = cmd + " -sDEVICE=" + device + " -dBATCH";
cmd = cmd + " -q -r" + resolution + " " + filename + tail;
// Execute command line and see if we can do it
try {
System (cmd: cmd);
} catch { // "status" object gets the error message
print status.message;
return;
}
// If we made it, get the list of page(s) generated. We need to get data
// to memory and remove the file.
INTEGER i;
STRING i_str, fname;
ELFLIST imgNames;
// Limit it to less than 1000 pages
cmd = " ";
for (i=1; i<1000; i++) {
// Compose the file name
if (i<10)
i_str = "0" + i;
else
i_str = i;
fname = tempname + i_str + "." + device;
if ( new (FILE, path: fname).isFile() ) {
if ( device == "jpeg" )
imgs.insert (entry: i-1,
obj: readjpg (filename:fname, compressed:1, rawcolor:1).exec() );
else
imgs.insert (entry: i-1,
obj: readimage (filename:fname).exec() );
cmd = cmd + " " + fname;
}
else
break;
}
System (cmd: "rm " + cmd);
// A list of images is returned through the "imgs" variable
}